﻿Imports System.Data.OleDb
Public Class Register
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        RegisterUser.ContinueDestinationPageUrl = Request.QueryString("ReturnUrl")
    End Sub

    Protected Sub RegisterUser_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles RegisterUser.CreatedUser
        FormsAuthentication.SetAuthCookie(RegisterUser.UserName, False)

        Dim continueUrl As String = RegisterUser.ContinueDestinationPageUrl
        If String.IsNullOrEmpty(continueUrl) Then
            continueUrl = "~/"
        End If

        'Adding new users' information to UserProfiles table 
        Dim conn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
        Dim sql As String = "INSERT INTO UserProfiles (UserName) VALUES (@f1)"
        Dim cmdDB = New OleDbCommand(sql, conn)
        conn.Open()
        cmdDB.CommandType = CommandType.Text
        'We used RegisterUser.UserName instead of User.Identity.Name, because the new user name is not exist yet
        cmdDB.Parameters.AddWithValue("@f1", RegisterUser.UserName)
        cmdDB.ExecuteNonQuery()
        Response.Redirect("~/ProfilesEdit.aspx")
    End Sub
End Class